﻿using System.Threading.Tasks;
using JoyfulHomeJourney.BackEnd.Infrastructure.Dtos.Requests;
using JoyfulHomeJourney.BackEnd.Infrastructure.Dtos.Responses;
using JoyfulHomeJourney.BackEnd.Server.Instances.Extends.Responses;
using JoyfulHomeJourney.BackEnd.Server.Interfaces;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace JoyfulHomeJourney.BackEnd.Api.Admin.Controllers
{
    public class LoginController : BaseController
    {
        private readonly ILoginServer _loginServer;

        public LoginController(ILoginServer loginServer)
        {
            _loginServer = loginServer;
        }
        /// <summary>
        /// 管理员登录
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> AdminLogin(RequestLoginDto dto)
        {
            return Send(await _loginServer.LoginAsync(dto,"admin"));
        }
        /// <summary>
        /// 汽车店登录
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> CarShopLogin(RequestLoginDto dto)
        {
            return Send(await _loginServer.LoginAsync(dto,"carShop"));
        }
        /// <summary>
        /// 用户登录
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> UserLogin(RequestLoginDto dto)
        {
            return Send(await _loginServer.LoginAsync(dto,"user"));
        }
        /// <summary>
        /// 员工登录
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> employLogin(RequestLoginDto dto)
        {
            return Send(await _loginServer.LoginAsync(dto, "employee"));
        }
        /// <summary>
        /// 获取当前员工账号信息
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        [TypeFilter(typeof(CheckLoginFilter), Arguments = new object[] { "employee" })]
        public IActionResult Getemploy()
        {
            return Send(ResponseApiDto.Success("数据已获取", _account.ToResponseDto()));
        }
        /// <summary>
        /// 获取当前账号信息
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        [TypeFilter(typeof(CheckLoginFilter), Arguments = new object[] { "admin" })]
        public IActionResult GetCurrentInfo()
        {
            return Send(ResponseApiDto.Success("数据已获取", _account.ToResponseDto()));
        }
        /// <summary>
        /// 获取当前汽车店账号信息
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        [TypeFilter(typeof(CheckLoginFilter), Arguments = new object[] { "carShop" })]
        public IActionResult GetCurrentCarShopInfo()
        {
            return Send(ResponseApiDto.Success("数据已获取", _account.ToResponseDto()));
        }
        /// <summary>
        /// 获取当前用户账号信息
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        [TypeFilter(typeof(CheckLoginFilter), Arguments = new object[] { "user" })]
        public IActionResult GetCurrentUserInfo()
        {
            return Send(ResponseApiDto.Success("数据已获取", _account.ToResponseDto()));
        }
        /// <summary>
        /// 抛出一个错误
        /// </summary>
        /// <exception cref="System.Exception"></exception>
        [HttpGet]
        public void Error()
        {
            throw new System.Exception("出错了");
        }
        /// <summary>
        /// 获取所有员工账号信息
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        [TypeFilter(typeof(CheckLoginFilter), Arguments = new object[] { "employee" })]
        public async Task<IActionResult> Get_employ()
        {
            return Send(await _loginServer.Get_employ());
        }

    }
}